import 'package:flutter/material.dart';

class MyApp2 extends StatefulWidget {
  const MyApp2({super.key});

  @override
  State<MyApp2> createState() {
    debugPrint('创建阶段');
    return _MyApp2State();
  }
  
}

class _MyApp2State extends State<MyApp2> {
  int age = 88;
  @override
  void initState() {
    //  implement initState
    debugPrint('初始化数据');
    super.initState();
  }

  @override
  void didChangeDependencies() {
    debugPrint('更新阶段');
    //  implement didChangeDependencies
    super.didChangeDependencies();
  }

  @override
  void deactivate() {
    debugPrint('销毁阶段');
    //  implement deactivate
    super.deactivate();
  }

// 构建阶段，会在生命周期内执行多次
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.cyanAccent,
              title: const Text('有状态组件'),
              centerTitle: true,
            ),
            body: Center(
                child: Text(
              '早上坏 $age',
              textDirection: TextDirection.rtl,
              style: const TextStyle(fontSize: 66.66),
            )),
            floatingActionButton: FloatingActionButton(
              onPressed: () {
                setState(() {
                  age--;
                });
              },
              child:const Icon(Icons.remove)
            )));
  }
}
